package com.world.business.texture.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.world.business.texture.domain.Texture;
import com.world.business.texture.domain.query.TextureAddRequest;
import com.world.business.texture.domain.query.TexturePageRequest;
import com.world.business.texture.domain.vo.TextureVO;
import com.world.business.texture.service.ITextureService;
import com.world.common.controller.BaseController;
import com.world.common.domain.PageResult;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 材质 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-07-27
 */
@Api(tags = "材质")
@RestController
@RequestMapping("/texture")
public class TextureController extends BaseController<Texture> {

    @Resource
    private ITextureService textureService;

    /**
     * 列表
     *
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 10:04
     */
    @ApiOperation("列表")
    @GetMapping("list")
    public ResponseData<List<TextureVO>> list() {
        List<Texture> list = textureService.list();
        return new SuccessResponseData<>(BeanUtil.copyToList(list, TextureVO.class));
    }

    /**
     * 分页-列表
     *
     * @param request 请求参数
     * @return {@link ResponseData < PageResult>}
     * @author WangYX
     * @date 2023/07/28 10:17
     */
    @ApiOperation("分页-列表")
    @GetMapping("/page")
    public ResponseData<PageResult<TextureVO>> page(TexturePageRequest request) {
        //1.分页条件
        Page<Texture> page = startPage(request);
        //2.查询条件
        LambdaQueryWrapper<Texture> queryWrapper = Wrappers.lambdaQuery(Texture.class);
        Page<Texture> result = textureService.page(page, queryWrapper);
        //3.结果转化
        PageResult<TextureVO> pageResult = getPageResult(result, TextureVO.class);
        return new SuccessResponseData<>(pageResult);
    }

    /**
     * 新增
     *
     * @param request 新增请求参数
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 10:34
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseData<Long> add(@RequestBody TextureAddRequest request) {
        return new SuccessResponseData<>(textureService.add(request));
    }

}
